function Total688TC(val){
	var soloaihop6884=document.getElementById('sohoploai688TC').value;
	for($i=1;$i<=soloaihop6884;$i++){
		var valnhan = document.getElementById('sel_nhan1'+$i).value;
		if(valnhan==0){
			var sohop = document.getElementById('soluonghop688TC'+$i).value;
			var sotien = parseInt(sohop)*688000;
			document.getElementById('thanhtien688TC'+$i).value = number_format(sotien);
		}
		if(valnhan==1){
			var sohop = document.getElementById('soluonghop688TC'+$i).value;
			var sotien = parseInt(sohop)*788000;
			document.getElementById('thanhtien688TC'+$i).value = number_format(sotien);
		}
	}
	var soloai6884 = document.getElementById('sohoploai688TC').value;
	if(soloai6884 == 1){
		var tronggiobac=document.getElementById('soluonghopgiobac').value;
		var tronggiovang=document.getElementById('soluonghopgiovang').value;
		var trong6 = document.getElementById('soluonghop688').value;
		var trong8 = document.getElementById('soluonghop888').value;
		var trong8extra = document.getElementById('soluonghop888extra').value;
		var trong64 = document.getElementById('soluonghop688TC1').value;
		var tongtiengiobac = parseInt(tronggiobac)*1000000;
		var tongtiengiovang = parseInt(tronggiovang)*1200000;
		var tongtien688 = parseInt(trong6)*688000;
		var tongtien888 = parseInt(trong8)*888000;
		var tongtien888extra = parseInt(trong8extra)*988000;
		var nhan16884=document.getElementById('sel_nhan11').value;if(nhan16884=="0"){var tongtien68841=parseInt(trong64)*688000;}else{var tongtien68841=parseInt(trong64)*788000;}
		if( tronggiobac=="" || tronggiovang=="" || trong6=="" || trong8=="" || trong8extra=="" || trong64=="" ){
			if(tronggiobac==""){
				document.getElementById('soluonghopgiobac').value = 0;
				document.getElementById('thanhtiengiobac').value = 0;
			}
			if(tronggiovang==""){
				document.getElementById('soluonghopgiovang').value = 0;
				document.getElementById('thanhtiengiovang').value = 0;
			}
			if(trong6==""){
				document.getElementById('soluonghop688').value = 0;
				document.getElementById('thanhtien688').value = 0;
			}
			if(trong8==""){
				document.getElementById('soluonghop888').value = 0;
				document.getElementById('thanhtien888').value = 0;
			}
			if(trong8extra==""){
				document.getElementById('soluonghop888extra').value = 0;
				document.getElementById('thanhtien888extra').value = 0;
			}
			if(trong64==""){
				document.getElementById('soluonghop688TC1').value = 0;
				document.getElementById('thanhtien688TC1').value = 0;
			}	
		}
		else{
			document.getElementById('soluonghopgiobac').value = tronggiobac;
			document.getElementById('thanhtiengiobac').value = number_format(tongtiengiobac);
			document.getElementById('soluonghopgiovang').value = tronggiovang;
			document.getElementById('thanhtiengiovang').value = number_format(tongtiengiovang);
			document.getElementById('soluonghop688').value = trong6;
			document.getElementById('thanhtien688').value = number_format(tongtien688);
			document.getElementById('soluonghop888').value = trong8;
			document.getElementById('thanhtien888').value = number_format(tongtien888);
			document.getElementById('soluonghop888extra').value = trong8extra;
			document.getElementById('thanhtien888extra').value = number_format(tongtien888extra);
			document.getElementById('soluonghop688TC1').value = trong64;
			document.getElementById('thanhtien688TC1').value = number_format(tongtien68841);
			document.getElementById('sohop688TC').value = trong64;
			document.getElementById('sotien688TC').value = tongtien68841;
		}
		var tongsohop = parseInt(tronggiobac) + parseInt(tronggiovang) + parseInt(trong6) + parseInt(trong8) + parseInt(trong8extra) + parseInt(trong64);
		document.getElementById('tongsohop').value = tongsohop;
		var tongsotien = parseInt(tongtiengiobac) + parseInt(tongtiengiovang) +  parseInt(tongtien688) + parseInt(tongtien888)+ parseInt(tongtien888extra) + parseInt(tongtien68841);
		document.getElementById('tongsotien').value = number_format(tongsotien);
		var sothevip = document.getElementById('sothevip').value;
		var discount = 0;
		if(sothevip !=""){
			if(sothevip>100000 && sothevip<139999 || sothevip>10000 && sothevip<39999 || sothevip>880010000000 && sothevip<880013999999){
				if(tongsohop<5){
					discount = (10*(tongsotien))/100;
					var valdiscount = 10;
				}
				else if(tongsohop>=5 && tongsohop <=20){
					discount = (15*(tongsotien))/100;
					var valdiscount = 15;
				}
				else if(tongsohop >=21){
					discount = (20*(tongsotien))/100;
					var valdiscount = 20;
				}
			}
			else{
				if(tongsohop<5){
					discount = (10*(tongsotien))/100;
					var valdiscount = 10;
				}
				else if(tongsohop>=5 && tongsohop <=20){
					discount = (15*(tongsotien))/100;
					var valdiscount = 15;
				}
				else if(tongsohop >=21){
					discount = (20*(tongsotien))/100;
					var valdiscount = 20;
				}
			}
		}
		else{
			if(tongsohop<5){
				discount = 0;
				var valdiscount = 0;
			}
			else if(tongsohop>=5 && tongsohop <=20){
				discount = (10*(tongsotien))/100;
				var valdiscount = 10;
			}
			else if(tongsohop>=21 && tongsohop<=50){
				discount = (15*(tongsotien))/100;
				var valdiscount = 15;
			}
			else if(tongsohop > 50){
				discount = (20*(tongsotien))/100;
				var valdiscount = 20;
			}
		}
		$('#discount').html(valdiscount);
		document.getElementById('chietkhau').value = number_format(discount);
		var thanhtien = parseInt(tongsotien) - parseInt(discount);
		var thue = parseInt(thanhtien)*0.1;
		document.getElementById('thue').value = number_format(thue);
		var tiencongthue = parseInt(thanhtien) + parseInt(thue);
		document.getElementById('grandtotal').value = number_format(tiencongthue);
	}
	else{
		var tronggiobac=document.getElementById('soluonghopgiobac').value;
		var tronggiovang=document.getElementById('soluonghopgiovang').value;
		var trong6 = document.getElementById('soluonghop688').value;
		var trong8 = document.getElementById('soluonghop888').value;
		var trong8extra = document.getElementById('soluonghop888extra').value;
		var trong64 = document.getElementById('soluonghop688TC1').value;
		var tongtiengiobac = parseInt(tronggiobac)*1000000;
		var tongtiengiovang = parseInt(tronggiovang)*1200000;
		var tongtien688 = parseInt(trong6)*688000;
		var tongtien888 = parseInt(trong8)*888000;
		var tongtien888extra = parseInt(trong8extra)*988000;
		var nhan16884=document.getElementById('sel_nhan11').value;if(nhan16884=="0"){var tongtien68841=parseInt(trong64)*688000;}else{var tongtien68841=parseInt(trong64)*788000;}
		if( tronggiobac=="" || tronggiovang=="" || trong6=="" || trong8=="" || trong8extra=="" || trong64=="" ){
			if(tronggiobac==""){
				document.getElementById('soluonghopgiobac').value = 0;
				document.getElementById('thanhtiengiobac').value = 0;
			}
			if(tronggiovang==""){
				document.getElementById('soluonghopgiovang').value = 0;
				document.getElementById('thanhtiengiovang').value = 0;
			}
			if(trong6==""){
				document.getElementById('soluonghop688').value = 0;
				document.getElementById('thanhtien688').value = 0;
			}
			if(trong8==""){
				document.getElementById('soluonghop888').value = 0;
				document.getElementById('thanhtien888').value = 0;
			}
			if(trong8extra==""){
				document.getElementById('soluonghop888extra').value = 0;
				document.getElementById('thanhtien888extra').value = 0;
			}
			if(trong64==""){
				document.getElementById('soluonghop688TC1').value = 0;
				document.getElementById('thanhtien688TC1').value = 0;
			}	
		}
		else{
			document.getElementById('soluonghopgiobac').value = tronggiobac;
			document.getElementById('thanhtiengiobac').value = number_format(tongtiengiobac);
			document.getElementById('soluonghopgiovang').value = tronggiovang;
			document.getElementById('thanhtiengiovang').value = number_format(tongtiengiovang);
			document.getElementById('soluonghop688').value = trong6;
			document.getElementById('thanhtien688').value = number_format(tongtien688);
			document.getElementById('soluonghop888').value = trong8;
			document.getElementById('thanhtien888').value = number_format(tongtien888);
			document.getElementById('soluonghop888extra').value = trong8extra;
			document.getElementById('thanhtien888extra').value = number_format(tongtien888extra);
			var totalhop6884 = 0;
			var total6884 = 0;
			for($i=1;$i<=soloai6884;$i++){
				var trong64 = document.getElementById('soluonghop688TC'+$i).value;
				totalhop6884 = parseInt(trong64) + parseInt(totalhop6884);
				var nhan16884		= document.getElementById('sel_nhan1'+$i).value;
					if(nhan16884=="0"){var tongtien68841=parseInt(trong64)*688000;}
					else{var tongtien68841=parseInt(trong64)*788000;}
				total6884 = parseInt(tongtien68841) + parseInt(total6884);
				document.getElementById('thanhtien688TC'+$i).value= number_format(tongtien68841);
			}
			document.getElementById('sohop688TC').value = totalhop6884;
			document.getElementById('sotien688TC').value = number_format(total6884);
		}
		var tongsohop = parseInt(tronggiobac) + parseInt(tronggiovang) + parseInt(trong6) + parseInt(trong8) + parseInt(trong8extra) + parseInt(totalhop6884);
		document.getElementById('tongsohop').value = tongsohop;
		var tongsotien = parseInt(tongtiengiobac) +  parseInt(tongtiengiovang) +  parseInt(tongtien688) + parseInt(tongtien888)+ parseInt(tongtien888extra) + parseInt(total6884);
		document.getElementById('tongsotien').value = number_format(tongsotien);
		var sothevip = document.getElementById('sothevip').value;
		var discount = 0;
		if(sothevip !=""){
			if(sothevip>100000 && sothevip<139999 || sothevip>10000 && sothevip<39999 || sothevip>880010000000 && sothevip<880013999999){
				if(tongsohop<5){
					discount = (10*(tongsotien))/100;
					var valdiscount = 10;
				}
				else if(tongsohop>=5 && tongsohop <=20){
					discount = (15*(tongsotien))/100;
					var valdiscount = 15;
				}
				else if(tongsohop >=21){
					discount = (20*(tongsotien))/100;
					var valdiscount = 20;
				}
			}
			else{
				if(tongsohop<5){
					discount = (10*(tongsotien))/100;
					var valdiscount = 10;
				}
				else if(tongsohop>=5 && tongsohop <=20){
					discount = (15*(tongsotien))/100;
					var valdiscount = 15;
				}
				else if(tongsohop >=21){
					discount = (20*(tongsotien))/100;
					var valdiscount = 20;
				}
			}
		}
		else{
			if(tongsohop<5){
				discount = 0;
				var valdiscount = 0;
			}
			else if(tongsohop>=5 && tongsohop <=20){
				discount = (10*(tongsotien))/100;
				var valdiscount = 10;
			}
			else if(tongsohop>=21 && tongsohop<=50){
				discount = (15*(tongsotien))/100;
				var valdiscount = 15;
			}
			else if(tongsohop > 50){
				discount = (20*(tongsotien))/100;
				var valdiscount = 20;
			}
		}
		$('#discount').html(valdiscount);
		document.getElementById('chietkhau').value = number_format(discount);
		var thanhtien = parseInt(tongsotien) - parseInt(discount);
		var thue = parseInt(thanhtien)*0.1;
		document.getElementById('thue').value = number_format(thue);
		var tiencongthue = parseInt(thanhtien) + parseInt(thue);
		document.getElementById('grandtotal').value = number_format(tiencongthue);
	}
}
function addthemhop(i){
	var k = parseInt(i)+1;
	var htmlhopmoi1 = '<td id="loaihop688TC">Hộp 688-4</td><td>';
	var htmlhopmoi2 = '<select name="sel_nhan1'+i+'" class="sel_nhan1" id="sel_nhan1'+i+'" onchange="Total688TC(this.value);"><option value="0">Gà quay</option><option value="1">Gà quay vi cá</option></select><select name="sel_nhan2'+i+'" class="sel_nhan2" id="sel_nhan2'+i+'"><option value="0">--- Chọn nhân ---</option><option value="Khoai môn">Khoai môn</option><option value="Đậu đỏ">Đậu đỏ</option><option value="Đậu xanh">Đậu xanh</option><option value="Hạt sen">Hạt sen</option><option value="Trà xanh hạt sen">Trà xanh hạt sen</option></select><select name="sel_nhan3'+i+'" class="sel_nhan3" id="sel_nhan3'+i+'"><option value="0">--- Chọn nhân ---</option><option value="Khoai môn">Khoai môn</option><option value="Đậu đỏ">Đậu đỏ</option><option value="Đậu xanh">Đậu xanh</option><option value="Hạt sen">Hạt sen</option><option value="Trà xanh hạt sen">Trà xanh hạt sen</option></select><select name="sel_nhan4'+i+'" class="sel_nhan4" id="sel_nhan4'+i+'"><option value="0">--- Chọn nhân ---</option><option value="Khoai môn">Khoai môn</option><option value="Đậu đỏ">Đậu đỏ</option><option value="Đậu xanh">Đậu xanh</option><option value="Hạt sen">Hạt sen</option><option value="Trà xanh hạt sen">Trà xanh hạt sen</option></select></td>';
	var htmlhopmoi3 = '<td><input type="text" id="soluonghop688TC'+i+'" name="soluonghop688TC'+i+'" class="soluonghop" value="0" onBlur="Total688TC()" onkeydown="return checkkytu(event)" /></td>';
	var htmlhopmoi4 = '<td valign="middle"><span class="dong"> VND</span><input type="text" id="thanhtien688TC'+i+'" name="thanhtien688TC'+i+'" class="thanhtien" value="0" readonly></td>';
	var htmlhopmoi = htmlhopmoi1 + htmlhopmoi2 + htmlhopmoi3 + htmlhopmoi4;
	$('.addthem'+i).html(htmlhopmoi);
	document.getElementById('addmoi'+i).style.display="none";
	document.getElementById('addmoi'+k).style.display="block";
	var sohoploai6884 = document.getElementById('sohoploai688TC').value;
	sohoploai6884 = parseInt(sohoploai6884)+1;
	document.getElementById('sohoploai688TC').value = sohoploai6884;
}
function menutophienan(){
	var displaynav = document.getElementById('navmobild').style.display;
	if(displaynav=="block"){
		var displaynav = document.getElementById('navmobild').style.display = "none";
	}
	else if(displaynav=="none"){
		var displaynav = document.getElementById('navmobild').style.display = "block";
	}
}
function checkkytu(e){
	var unicode=e.keyCode;

 	if(unicode == 97 || unicode == 98 || unicode == 99 || unicode == 100 || unicode == 101 || unicode == 102 || unicode == 103 || unicode == 104 || unicode == 105 || unicode == 9)
 		return true;
	if(unicode!=8){
		if(unicode <48 || unicode >57){
			return false;
		}
	}
}
function number_format(number, decimals, dec_point, thousands_sep){
	number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
	var n = !isFinite(+number) ? 0 : +number,
		prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
		sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
		dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
		s = '',
		toFixedFix = function (n, prec) {
			var k = Math.pow(10, prec);
			return '' + Math.round(n * k) / k;
		};
		s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
		if (s[0].length > 3) {
			s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
		}
		if ((s[1] || '').length < prec) {
			s[1] = s[1] || '';
			s[1] += new Array(prec - s[1].length + 1).join('0');
		}
	return s.join(dec);
}